package com.lxhotel.agentmcp.tool;

import com.lxhotel.agentmcp.domain.response.HotelBookResponse;
import com.lxhotel.agentmcp.domain.response.HotelRoomTypeInventoryResponse;
import com.lxhotel.agentmcp.entity.Hotel;
import com.lxhotel.agentmcp.mapper.HotelMapper;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;


@Service
public class HotelInventoryTool {

    @Autowired
    private HotelMapper hotelMapper;

    @Tool(description = "根据日期查询酒店的房量信息")
    public HotelBookResponse selectHotelRoomTypeInventoryByBookingDate(@ToolParam(description = "预定日期") String bookingDate, @ToolParam(description = "酒店名称") String hotelName) {
        List<Hotel> hotelList = hotelMapper.selectByHotelNameLike(hotelName);
        if (ObjectUtils.isEmpty(hotelList)) {
            throw new IllegalArgumentException("酒店不存在");
        }
        if (hotelList.size()>1) {
            throw new IllegalArgumentException("查询到多个酒店，请提供更详细的信息");
        }
        List<HotelRoomTypeInventoryResponse> roomTypeResponses = hotelMapper.selectHotelRoomTypeInventoryByBookingDate(bookingDate, hotelList.get(0).getId());
        return HotelBookResponse.builder().hotel(hotelList.get(0))
                .hotelRoomTypeList(roomTypeResponses).build();
    }

}
